<?php

namespace App\Admin\Controllers\Agent;

use App\model\agent\AgentSlider;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class AgentSlier extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '轮播图管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new AgentSlider);

        $grid->column('id', __('Id'));
        $grid->column('name', '轮播图')->display(function ($value){
            return \Storage::url($value);
        })->image('',100,100);
        $grid->column('url', '链接');
        $grid->column('sort','排序');
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(AgentSlider::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('sort', __('Sort'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new AgentSlider);

        $form->image('name', '轮播图')->required();
        $form->text('url','链接');
        $form->number('sort', __('排序'))->help('数字越大，排序越靠前');

        return $form;
    }
}
